package com.example.behaviorpattern.visitor.impl;

import com.example.behaviorpattern.visitor.Element;
import com.example.behaviorpattern.visitor.Visitor;

/**
 * 具体访问者A
 *
 * @author yaojianfeng
 */
public class ConcreteVisitorA implements Visitor {
    @Override
    public void visit(Element element) {
        element.operation(element1 -> {
                    // 具体操作
                    if (element1 instanceof ConcreteElementA elementA) {
                        visitA(elementA);
                    } else if (element1 instanceof ConcreteElementB elementB) {
                        System.out.println("ConcreteVisitorA 访问:" + elementB.name());
                        System.out.println("ConcreteVisitorA 访问:" +
                                elementB.name() + "的value是 " + elementB.value());
                    } else {
                        System.out.println("该元素类型不支持");
                    }
                }
        );
    }

    private void visitA(ConcreteElementA elementA) {
        System.out.println("ConcreteVisitorA 访问 ConcreteElementA: "
                + elementA.name() + "的value是 " + elementA.value());
    }

}